<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom title="我的简历" :isAppBtn="false">
			<!-- <view slot="right" class="font30 lh44 mr24" @click="goPage('/recruit/user/vitaSet')">简历设置</view> -->
		</HeadCustom>
		<view class="wrap">
			<view class="card userInfo fboxRow Ycenter">
				<image class="avatar" :src="fromData.avatar" mode="aspectFill" @click="goApp"></image>
				<view class="fboxCol flex1" @click="goPage('/recruit/user/personal')">
					<view class="name font34">{{ fromData.realName }}
						<image v-if="fromData.isAuth" class="img_sm"
							src="https://ebc-prod.cdn.benwunet.com/uni-static/workplace/icon-s.png" mode=""></image>
					</view>
					<view class="age font30 color-ACB4C7">{{ getMymethod(fromData.birthday, 'Y') }}</view>
				</view>
				<view class="progress fboxRow Ycenter" @click="goPage('/recruit/user/personal')">
					<text class="font26">{{ fromData.resumeCompletePercent || 0 }}%，{{ fromData.enableStatus == 1 ? '已启用' : '未启用' }}</text>
					<text class="bwfont bw-arrow-right color-ACB4C7 font24"></text>
				</view>
			</view>
			<view class="card fboxRow Ycenter">
				<view class="tit font34 flex1">
					我的身份
					<text style="color:#D25941">*</text>
				</view>
				<view class="action">
					<view class="btn-group font26 fboxRow Ycenter">
						<view class="btn fboxRow Ycenter" @click="statusChange(1)"
							:class="[fromData.resumeIdentity == 1 ? 'bg-linear' : 'bg-38383D']">
							职场人
						</view>
						<view class="btn fboxRow Ycenter" @click="statusChange(2)"
							:class="[fromData.resumeIdentity == 2 ? 'bg-linear' : 'bg-38383D']">
							应届生/在校生
						</view>
					</view>
				</view>
			</view>
			<view class="card fboxRow Ycenter" @click="itemTap('gmtTakeJob')">
				<view class="tit font34 flex1">
					参加工作时间
					<text style="color:#D25941">*</text>
				</view>
				<view class="action fboxRow Ycenter font26">
					<text v-if="fromData.gmtTakeJob">{{ fromData.gmtTakeJob.replace('-', '.') }}</text>
					<text v-else class="color-6B707C">请设置</text>
					<text class="bwfont bw-arrow-right color-ACB4C7 font24"></text>
				</view>
			</view>
			<view class="card fboxRow Ycenter" @click="itemTap('education')">
				<view class="tit font34 flex1">
					最高学历
					<text style="color:#D25941">*</text>
				</view>
				<view class="action fboxRow Ycenter font26">
					<text v-if="fromData.education">{{ gainData(fromData.education, 'educationList').label }}</text>
					<text v-else class="color-6B707C">请设置</text>
					<text class="bwfont bw-arrow-right color-ACB4C7 font24"></text>
				</view>
			</view>
			<view class="card" @click="goPage('/recruit/user/vita-textarea?pageType=advantage')">
				<view class=" fboxRow Ycenter">
					<view class="tit font34 flex1">
						个人优势
						<text style="color:#D25941">*</text>
					</view>
					<view class="action"><text class="bwfont bw-xiugai color-ACB4C7 font30"></text></view>
				</view>
				<view class="line"></view>
				<view class="con font26">
					<template v-if="fromData.advantage">
						<view class="color-ACB4C7 lh44" style="white-space: pre-wrap;" v-html="fromData.advantage">
						</view>
						<Tags :list="fromData.resumeKeywordList"></Tags>
					</template>
					<text v-else class="color-6B707C">填写个人优势，突出自己的核心优势</text>
				</view>
			</view>
			<view class="card fboxRow Ycenter" @click="itemTap('voice')">
				<view class="tit font34 flex1">
					语音介绍
				</view>
				<view class="action fboxRow Ycenter font26">
					<text v-if="fromData.isVoiceUrl">已设置</text>
					<text v-else class="color-ACB4C7">未设置</text>
					<text class="bwfont bw-arrow-right color-ACB4C7 font24"></text>
				</view>
			</view>
			<view class="card fboxRow Ycenter" @click="itemTap('video')">
				<view class="tit font34 flex1">
					视频介绍
				</view>
				<view class="action fboxRow Ycenter font26">
					<text v-if="fromData.isVideoUrl">已设置</text>
					<text v-else class="color-ACB4C7">未设置</text>
					<text class="bwfont bw-arrow-right color-ACB4C7 font24"></text>
				</view>
			</view>
			<view class="card" @click="goPage('/recruit/user/vita-expect')">
				<view class="fboxRow Ycenter">
					<view class="tit font34 flex1">
						求职意向
						<text style="color:#D25941">*</text>
					</view>
					<view class="action"><text class="bwfont bw-xiugai color-ACB4C7 font30"></text></view>
				</view>
				<view class="line"></view>
				<view class="con font26">
					<template v-if="fromData.expectCityName">
						<view class="font30">{{ fromData.expectPositionList.toString() }}</view>
						<view class="color-ACB4C7 mt24">
							<view class="">地区： {{ fromData.expectCityName }}</view>
							<view class="fboxRow">
								<view class="">
									行业：
								</view>
								<view class="flex1">
									{{ fromData.expectIndustryList.toString() }}
								</view>
							</view>
							<view class="">
								薪资：
								<text v-if="fromData.salaryMin == 0">面议</text>
								<text v-else>{{ unitNum(fromData.salaryMin) }}-{{ unitNum(fromData.salaryMax) }}</text>
							</view>
						</view>
					</template>
					<text v-else class="color-6B707C">填写求职意向，目标更明确</text>
				</view>
			</view>
			<!-- <view class="card fboxRow Ycenter" @click="goPage('/recruit/user/vita-file')">
				<view class="tit font34 flex1">附件简历</view>
				<view class="action fboxRow Ycenter">
					<text v-if="fromData.accessoryData && fromData.accessoryData.fileUrl"
						class="color-ACB4C7">已上传</text>
					<text v-else class="color-6B707C">未上传</text>
					<text class="bwfont bw-arrow-right color-ACB4C7 font24"></text>
				</view>
			</view> -->
			<VitaMore :fromData="fromData" type="1" />
			<template
				v-if="!(fromData.workExperienceList && fromData.workExperienceList.length) || !(fromData.projectExperienceList && fromData.projectExperienceList.length)">
				<view class="more-item fboxRow Ycenter Xcenter font26 color-6B707C" v-if="!isMoreItem"
					@click="moreItemTap">
					更多项
					<u-icon :name="isMoreItem ? 'arrow-left-double' : 'arrow-right-double'" size="30rpx" color="#98979C"></u-icon>
				</view>
			</template>
			<template v-if="isMoreItem">
				<VitaMore :fromData="fromData" type="2" />
			</template>
			<BottomFixed>
				<view class="btn-group-inner flex1 fboxRow Ycenter Xcenter">
					<view class="btn flex1 fboxRow Ycenter Xcenter font30 bg-border-btn" @click="getDownload">生成简历附件
					</view>
					<view class="btn flex1 fboxRow Ycenter Xcenter font30 color-141720 bg-linear" @click="goPage('view')">
						预览我的简历
					</view>
				</view>
			</BottomFixed>
		</view>
		<PickerBlack type="year-month" :isShow.sync="isDate" :val="dateVal" :minDate="startDate" :maxDate="endDate"
			@confirm="dateConfirm" />
		<PickerBlack :isShow.sync="isEducation" :list="educationList" @confirm="pickerEducation" />
	</view>
</template>

<script>
	import {
		currentMember,
		resumeInfo,
		resumeExportPdf
	} from '@/api/recruit.js';
	import {
		timestampToTime,
		getDate,
		getMymethod,
		unitNum,
		getRequest
	} from '@/static/js/common.js';
	import {
		gainData
	} from '../common/config.js';
	import PickerBlack from '../components/picker-black.vue';
	import Tags from '../components/tags.vue';
	import VitaMore from './vita-more.vue';
	import BottomFixed from '@/components/bottom-btn/fixed.vue'
	import {
		recruitMixins
	} from '../common/recruit.mixins.js';
	import {
		utf8to16,
		base64decode
	} from '@/static/js/Base64.js';
	export default {
		components: {
			PickerBlack,
			Tags,
			VitaMore,
			BottomFixed
		},
		mixins: [recruitMixins],
		data() {
			return {
				theme: getApp().globalData.appTheme,
				globalColor: getApp().globalData.globalColor,
				gainData: gainData,
				getMymethod: getMymethod,
				unitNum: unitNum,
				fromData: {
					accessoryData: {
						fileSize: '',
						fileUrl: '',
						gmtUpLoad: '',
						name: ''
					},
					advantage: '',
					age: 0,
					avatar: '',
					birthday: '',
					collectFlag: false,
					education: '',
					educationType: '',
					email: '',
					enableStatus: 0,
					expectCityId: '',
					expectCityName: '',
					expectIndustryList: [],
					expectPositionList: [],
					gender: '',
					gmtCreate: '',
					gmtModified: '',
					gmtTakeJob: '',
					// "id": "",
					inviteFlag: false,
					matchIndex: 0,
					memberId: '',
					projectExperienceList: [
						// {
						// 	"gmtEndWork": "",
						// 	"gmtStartWork": "",
						// 	"position": "",
						// 	"projectDescription": "",
						// 	"projectName": ""
						// }
					],
					realName: '',
					resumeCompletePercent: 0,
					resumeIdentity: 1,
					resumeKeywordList: [],
					salaryMax: '',
					salaryMin: '',
					showCardAll: 0,
					showCardCompany: 0,
					workExperienceList: [
						// {
						// 	"companyName": "",
						// 	"department": "",
						// 	"gmtEndWork": "",
						// 	"gmtStartWork": "",
						// 	"industry": "",
						// 	"jobContent": "",
						// 	"position": ""
						// }
					],
					workYears: ''
				},
				isMoreItem: false,
				isDate: false,
				isEducation: false,
				educationList: [gainData('list', 'educationList')],
				dateVal: ''
			};
		},
		onLoad(option) {
			if (option && option.benwu) {
				const benwu = utf8to16(base64decode(option.benwu))
				const token = {
					access_token: getRequest(benwu, 'token'),
					userId: getRequest(benwu, 'userId'),
					statusBarHeight: getRequest(benwu, 'statusBarHeight')
				}
				getApp().globalData.userId = token.userId
				getApp().globalData.statusBarHeight = token.statusBarHeight
				uni.setStorageSync('bw_params', JSON.stringify(token));
			}
		},
		onShow() {
			this.getInit();
		},
		computed: {
			startDate() {
				return getDate('start', 60);
			},
			endDate() {
				return getDate('end', 0);
			}
		},
		methods: {
			getDownload() {
				const {
					bw_link
				} = getApp().getBWData(['bw_link'])
				if (bw_link.isApp) {
					const data = {
						type: 'vitaArraybuffer',
						id: this.fromData.id,
						realName: this.fromData.realName
					}
					this.$bridge.callHandler('recruitHandler', data, () => {
						console.log('recruitHandler', '返回')
					})
				} else {
					resumeExportPdf({
						id: this.fromData.id
					}).then(res => {
						// let pdfData = ''; //pdfData是后端返回的文件流
						// let blob = new Blob([response], {
						// 	type: 'application/pdf;charset=UTF-8'
						// })
						// #ifdef H5
						let pdfData = res.data.filePath //创建预览路径	
						let downloadElement = document.createElement("a");
						downloadElement.href = pdfData
						downloadElement.download = res.data.fileName // 下载后文件名
						document.body.appendChild(downloadElement)
						downloadElement.click() // 点击下载
						document.body.removeChild(downloadElement) // 下载完成移除元素
						window.URL.revokeObjectURL(pdfData) // 释放掉blob对象
						// #endif
						
						// #ifdef MP
						uni.saveFile({ //文件保存到本地
							tempFilePath: res.data.filePath, //临时路径
							success: function(res) {
							  uni.showToast({
								icon: 'none',
								mask: true,
								title: '文件已保存!', 
								duration: 3000,
							  });
							}
						});
						// #endif
					})
				}
			},
			dateConfirm(e) {
				this.fromData.gmtTakeJob = timestampToTime(e.value, 'YM');
				this.isDate = false;
				this.postSave(this.fromData, 'renovate');
			},
			statusChange(type) {
				this.fromData.resumeIdentity = type;
				this.postSave(this.fromData, 'renovate');
			},
			moreItemTap() {
				this.isMoreItem = !this.isMoreItem;
			},
			getInit() {
				resumeInfo().then(res => {
					if (res.data) {
						this.fromData = res.data;
					} else {
						this.loading = 'not-data';
						this.getInfo();
					}
				});
			},
			getInfo() {
				currentMember().then(res => {
					if (res.data) {
						const {
							realName,
							birthday,
							avatar,
							gender,
							memberId,
							isAuth
						} = res.data;
						this.fromData.realName = realName;
						this.fromData.birthday = birthday;
						this.fromData.avatar = avatar;
						this.fromData.gender = gender;
						this.fromData.memberId = memberId;
						this.fromData.isAuth = isAuth
					}
				});
			},
			itemTap(e) {
				if (e == 'education') {
					this.isEducation = true;
				} else if (e == 'voice') {
					this.$pageTo('/recruit/user/vita-audio');
				} else if (e == 'video') {
					this.$pageTo('/recruit/user/vita-video');
				} else if (e == 'gmtTakeJob') {
					this.dateVal = this.fromData.gmtTakeJob ? new Date(this.fromData.gmtTakeJob).getTime() : new Date()
						.getTime();
					this.isDate = true;
				}
			},
			goPage(path, i) {
				getApp().globalData.vitaTemp = this.fromData;
				if (path == 'workExperience') {
					let parma = '';
					if (typeof i != 'undefined') {
						getApp().globalData.workExperience = this.fromData.workExperienceList[i];
						parma = '?index=' + i + '&isCon=1';
					} else {
						getApp().globalData.workExperience = {};
						parma = '?isCon=0';
					}
					this.$pageTo('/recruit/user/vita-workExperience' + parma);
				} else if (path == 'projectExperience') {
					let parma = '';
					if (typeof i != 'undefined') {
						getApp().globalData.projectExperience = this.fromData.projectExperienceList[i];
						parma = '?index=' + i + '&isCon=1';
					} else {
						getApp().globalData.projectExperience = {};
						parma = '?isCon=0';
					}
					this.$pageTo('/recruit/user/vita-projectExperience' + parma);
				} else if (path == 'view') {
					if (this.fromData.id) {
						this.$pageTo('/recruit/user/detail?pageType=0&id=' + this.fromData.id);
					} else {
						uni.showToast({
							icon: 'none',
							title: '请完善你的简历'
						});
					}
				} else if (path) {
					this.$pageTo(path);
				} else {
					this.$pageTo('/recruit/user/detail?pageType=0&id=' + this.fromData.id);
				}
			},
			goApp(type) {
				const data = {
					type: 'card',
					memberId: this.fromData.memberId
				}
				this.$bridge.callHandler('recruitHandler', data, () => {
					console.log('recruitHandler', '返回')
				})
			},
			pickerEducation(e) {
				this.isEducation = false;
				this.fromData.education = e.value[0].value;
				this.postSave(this.fromData, 'renovate');
			}
		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 32rpx 40rpx;
	}

	.img_sm {
		width: 40rpx;
		height: 40rpx;
		margin-left: 10rpx;
	}

	.card {
		padding: 32rpx;
		margin-bottom: 24rpx;
		background-color: var(--viewBgColor);
		border-radius: 12rpx
	}
	.card .bw-arrow-right{margin-left: 10rpx;}

	.userInfo .avatar {
		margin-right: 24rpx;
		width: 100rpx;
		height: 100rpx;
		border: 2rpx solid #f7f9ff;
		border-radius: 50%;
		overflow: hidden;
	}

	.userInfo .name {
		line-height: 50rpx;
		display: flex;
		align-items: center;
	}

	.userInfo .age {
		line-height: 44rpx;
	}
	.progress{color: var(--contourButtonTextColor);}

	.tags {}

	.tags .tag {
		margin: 16rpx 16rpx 16rpx 0;
		padding: 0 12rpx;
		height: 48rpx;
		border-radius: 8rpx;
	}

	.btn-group {
		border-radius: 8rpx;
		overflow: hidden;
	}

	.btn-group .btn {
		padding: 0 12rpx;
		height: 48rpx;
		color: var(--contentBgImageTitleColor)
	}
	.bg-38383D{background-color: var(--contentFontDarkColor);}

	.more-item {
		height: 70rpx;
		margin-bottom: 24rpx;
	}

	.card .con {
		line-height: 38rpx;
	}

	.line {
		margin: 32rpx 0;
		height: 1rpx;
		background: var(--backgroundDivisionColor);
	}

	.btn-group-inner .btn {
		height: 76rpx;
		border-radius: 12rpx;
		font-weight: 300;
	}

	.btn-group-inner .btn+.btn {
		margin-left: 30rpx;
	}

	// .fixed-btn .btn {
	// 	width: 570rpx;
	// 	height: 76rpx;
	// 	border-radius: 12rpx;
	// }
</style>